package cn.itcast.bos.transit.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.transit.InOutStorageInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.transit.dao.InOutStorageInfoDao;
import cn.itcast.bos.transit.dao.TransitInfoDao;
import cn.itcast.bos.transit.service.InOutStorageInfoService;

@Service
@Transactional
public class InOutStorageInfoServiceImpl implements InOutStorageInfoService{
	@Autowired
	private InOutStorageInfoDao inOutStorageInfoDao;
	@Autowired
	private TransitInfoDao transitInfoDao;
	
	@Override
	public void save(InOutStorageInfo t) {
		// TODO Auto-generated method stub
		TransitInfo transitInfo = transitInfoDao.getOne(t.getId());
		if(transitInfo.getStatus().equals("出入库中转")){
			t.setId(null);
			InOutStorageInfo inOutStorageInfo = inOutStorageInfoDao.save(t);
			transitInfo.getInOutStorageInfos().add(inOutStorageInfo);
			if(t.getOperation().equals("到达网点")){
				transitInfo.setStatus("到达网点");
			}
		}else{
			throw new RuntimeException("商品已到达网点，无法出入库");
		}
	
	}

}
